﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BIZ;
using System.Collections;

namespace JoyLibrary.Controllers
{
    [LoginRex]
    public class VipcenterController : Controller
    {
        //
        // GET: /Vipcenter/
        VipCenterOper vco= new VipCenterOper();
        public ActionResult Basic()
        {
            return View();
        }
        public ActionResult UpdateBasic()
        {
            return View();
        }
        public ActionResult ChangePass()
        {
            return View();
        }
        public ActionResult CostList()
        {
            return View();
        }
        public ActionResult Dlist(int id, string name)
        {
            DomainModel.UserInfo ui = (DomainModel.UserInfo)Session["user"];
            int pageno = Request["pageno"] == null ? 1 : int.Parse(Request["pageno"].ToString());//当前页
            int pagesite = 5;
            IList list = vco.DirectoryList(ui.u_id, id, pageno, pagesite);
            ViewData["list"] = list;
            ViewData["name"] = Server.UrlDecode(Request["name"]);
            return View();
        }

        public ActionResult readHistory()
        {
            DomainModel.UserInfo ui = (DomainModel.UserInfo)Session["user"];
            int pageno = Request["pageno"] == null ? 1 : int.Parse(Request["pageno"].ToString());//当前页
            int pagesite = 5;
            IList list = vco.LibraryBookIndentDetail(pageno, pagesite, ui.u_id);
            ViewData["list"] = list;

            return View();
        }

        public string delDirectory()
        {
            string id = Request.Form["id"];
            if (vco.checkUserSaveCount(int.Parse(id)))
                return "have";
            int count = vco.delDirectory(id);
            if (count > 0)
                return "y";
            else
                return "n";
        }
        public string addDirectory()
        {
            DomainModel.UserInfo ui = (DomainModel.UserInfo)Session["user"];
            string name = Request.Form["name"];
            vco.addDirectory(ui.u_id, name);
            return "y";
        }

        public string appraisal()
        {
            string id = Request.Form["id"];
            string appraisal = Request.Form["appraisal"];
            vco.appraisal(int.Parse(id), appraisal);
            return "y";
        }
        public string checkDirectoryName()
        {
            DomainModel.UserInfo ui = (DomainModel.UserInfo)Session["user"];
            string name = Request.Form["name"];
            if (vco.checkDirectoryName(ui.u_id, name.Trim()))
                return "have";
            else
                return "y";
        }
        //addDirectory
        public ActionResult DirectoryList()
        {
            DomainModel.UserInfo ui = (DomainModel.UserInfo)Session["user"];
            IList list = vco.getDirectoryList(ui.u_id.ToString());
            ViewData["list"] = list;
            return View();
        }


        public string delUserSave()
        {
            string ids = Request.Form["ids"];
            vco.delUserSave(ids);
            return "y";
        }

        public string recommend()
        {
            string id = Request.Form["id"];
            vco.recommend(int.Parse(id));
            return "y";
        }

        public ActionResult HistroyList()
        {
            return View();
        }
        public ActionResult CurrentList()
        {
            return View();
        }
        public JsonResult changepwd()
        {
            string newpwd = Request["newpwd"] == null ? "" : Request["newpwd"].ToString();
            string oldpwd = Request["oldpwd"] == null ? "" : Request["oldpwd"].ToString();
            DomainModel.UserInfo ui = (DomainModel.UserInfo)Session["user"];
            if(newpwd=="")
                return Json(1);//新密码为空
            if (ui.u_pass != BIZ.StringTool.md5(oldpwd, 16))
                return Json(0);//旧密码不对

            vco.changepwd(ui.u_id.ToString(), BIZ.StringTool.md5(newpwd, 16));
            ui.u_pass = BIZ.StringTool.md5(newpwd, 16);
            Session["user"] = ui;
            return Json(2);//成功
        }
    }
}
